#include "statsMenu.h"

StatsMenu::StatsMenu()
{
	this->menuIndex = 0;
	this->initInputFunc();
	this->MenuOn = false;
	this->menus[0].LoadFromFile("statsmenuItems.png");
	this->menus[1].LoadFromFile("statsmenuWeapons.png");
	this->menus[2].LoadFromFile("statsmenuAmor.png");
	this->menus[3].LoadFromFile("statsmenuMagic.png");
	this->menus[4].LoadFromFile("player.png");
	this->extra.SetImage(menus[4]);
	this->extra.Scale(2.f, 2.f);

}

void StatsMenu::draw(sf::RenderWindow &window)
{
	if(this->MenuOn)
	{
		this->Sprite.SetImage(menus[this->menuIndex]);
		this->Sprite.SetPosition(this->xPos, this->yPos);
		window.Draw(this->Sprite);
		this->extra.SetPosition(this->xPos + 34, this->yPos + 34);
		window.Draw(this->extra);
	}
}

void StatsMenu::initInputFunc()
{
	this->inputFunctions[3] = &statsMenuPlayer;
	this->inputFunctions[12] = &statsMenuLeft;
	this->inputFunctions[13] = &statsMenuRight;
	this->inputFunctions[21] = &nstatsMenuPlayer;
	this->inputFunctions[30] = &nstatsMenuLeft;
	this->inputFunctions[31] = &nstatsMenuRight;
	
}

void statsMenuLeft(void *object, void *extraData)
{
	StatsMenu* statsMenu = static_cast<StatsMenu*>(object);
	if(!statsMenu->keysPressed[12])
	{
		statsMenu->keysPressed[12] = true;
	}
}
void nstatsMenuLeft(void *object, void *extraData)
{
	StatsMenu* statsMenu = static_cast<StatsMenu*>(object);
	if(statsMenu->keysPressed[12])
	{
		statsMenu->menuIndex--;
		if(statsMenu->menuIndex == -1 )
		{
			statsMenu->menuIndex = 3;
		}
		statsMenu->keysPressed[12] = false;
	}
}
void statsMenuRight(void *object, void *extraData)
{
	StatsMenu* statsMenu = static_cast<StatsMenu*>(object);
	if(!statsMenu->keysPressed[13] )
	{
		statsMenu->keysPressed[13] = true;
	}
}
void nstatsMenuRight(void *object, void *extraData)
{
	StatsMenu* statsMenu = static_cast<StatsMenu*>(object);
	if(statsMenu->keysPressed[13])
	{
		statsMenu->menuIndex++;
		if(statsMenu->menuIndex == 4)
		{
			statsMenu->menuIndex = 0;
		}
		statsMenu->keysPressed[13] = false;
	}
}
void statsMenuPlayer(void *object, void *extraData)
{
	StatsMenu* statsMenu = static_cast<StatsMenu*>(object);
	if(!statsMenu->keysPressed[3])
	{
		statsMenu->keysPressed[3] = true;
	}
}
void nstatsMenuPlayer(void *object, void *extraData)
{
	StatsMenu* statsMenu = static_cast<StatsMenu*>(object);
	if(statsMenu->keysPressed[3])
	{
		statsMenu->MenuOn = false;
		statsMenu->keysPressed[3] = false;
		statsMenu->menuIndex = 0;
	}
}